package com.koron.ticket.workchange.ticketchangesecurityarrangement.service.impl;


import com.koron.bean.base.Response;
import com.koron.common.core.util.CodeTools;
import com.koron.ticket.workchange.ticketchangesecurityarrangement.bean.TicketChangeSecurityArrangement;
import com.koron.ticket.workchange.ticketchangesecurityarrangement.bean.TicketChangeSecurityArrangementQuery;
import com.koron.ticket.workchange.ticketchangesecurityarrangement.mapper.TicketChangeSecurityArrangementMapper;
import com.koron.ticket.workchange.ticketchangesecurityarrangement.service.TicketChangeSecurityArrangementService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (TicketChangeSecurityArrangement)表服务实现类
 *
 * @author 朱超
 * @since 2021-10-27 10:22:43
 */
@Service
public class TicketChangeSecurityArrangementServiceImpl implements TicketChangeSecurityArrangementService {

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("insert")
    public Response insert(SessionFactory factory, TicketChangeSecurityArrangement ticketChangeSecurityArrangement) {
        TicketChangeSecurityArrangementMapper mapper = factory.getMapper(TicketChangeSecurityArrangementMapper.class);
        String id = CodeTools.getCode32();
        ticketChangeSecurityArrangement.setId(id);
        mapper.insert(ticketChangeSecurityArrangement);
        return Response.success(id);
    }

    /**
     * 根据id删除单条数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public Response deleteById(SessionFactory factory, String id) {
        TicketChangeSecurityArrangementMapper mapper = factory.getMapper(TicketChangeSecurityArrangementMapper.class);
        mapper.deleteById(id);
        return Response.success("删除成功");
    }

    /**
     * 根据workTicketId删除相关数据
     *
     */
    @Override
    public void deleteByWorkTicketId(SessionFactory factory, String workTicketId) {
        TicketChangeSecurityArrangementMapper mapper = factory.getMapper(TicketChangeSecurityArrangementMapper.class);
        mapper.deleteByWorkTicketId(workTicketId);
    }

    /**
     * 更新数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public Response update(SessionFactory factory, TicketChangeSecurityArrangement ticketChangeSecurityArrangement) {
        TicketChangeSecurityArrangementMapper mapper = factory.getMapper(TicketChangeSecurityArrangementMapper.class);
        mapper.update(ticketChangeSecurityArrangement);
        return Response.success("更新成功");
    }

    /**
     * 根据id查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public Response getById(SessionFactory factory, String id) {
        TicketChangeSecurityArrangementMapper mapper = factory.getMapper(TicketChangeSecurityArrangementMapper.class);
        TicketChangeSecurityArrangementQuery query = new TicketChangeSecurityArrangementQuery();
        query.setId(id);
        TicketChangeSecurityArrangement ticketChangeSecurityArrangement = mapper.getSingle(query);
        return Response.success(ticketChangeSecurityArrangement);
    }

    @Override
    public TicketChangeSecurityArrangement getSingle(SessionFactory factory, TicketChangeSecurityArrangementQuery ticketChangeSecurityArrangementQuery) {
        TicketChangeSecurityArrangementMapper mapper = factory.getMapper(TicketChangeSecurityArrangementMapper.class);
        return mapper.getSingle(ticketChangeSecurityArrangementQuery);
    }

    @Override
    public List<TicketChangeSecurityArrangement> getList(SessionFactory factory, TicketChangeSecurityArrangementQuery ticketChangeSecurityArrangementQuery) {
        TicketChangeSecurityArrangementMapper mapper = factory.getMapper(TicketChangeSecurityArrangementMapper.class);
        return mapper.getList(ticketChangeSecurityArrangementQuery);
    }

}
